//
// Created by 原帅 on 2022/10/6.
//

#include "TestProcUnit.h"
#include "stdio.h"
#include "unistd.h"
#include "TestData.h"
#include "RMemory.h"
#include "RMemoryManger.h"
#include "RLog.h"
#include "Ree.h"
#include "RTCPConnetor.h"
#include "TestReeProc.h"
#include "RAcceptor.h"
#include "TestReeAcceptProc.h"
#include "RRepos.h"

int TestProcUnit::initProcess(int argc, char **argv) {

    RLogErr("this is a mircle")

//    RTCPConnetor* rtcpConnetor = new RTCPConnetor("127.0.0.1",9999);
//    rtcpConnetor->doConnect();
//    Ree::Inst().addResponder(rtcpConnetor->getSockfd(),READ_FD,new TestReeProc());
//
    RAcceptor rAcceptor(7777,SOCK_STREAM);
    rAcceptor.doListen();
    RRepos<int,RAcceptor>::Inst().getRepos().insert(pair<int,RAcceptor>(rAcceptor.getSockfd(),rAcceptor));

    Ree::Inst().addResponder(rAcceptor.getSockfd(), READ_FD, new TestReeAcceptProc());

    return 0;
}

int TestProcUnit::process() {
//    RLogDbg("TEST------------------------------" );
    Ree::Inst().processEvent();

//    RMemory<TestData> * testDataMemroy = RMemoryManger::Inst().getRMemoryWithKey<TestData>(111);
//    if (testDataMemroy == nullptr) {
//        sleep(10);
//        return 0;
//    }
//    if (testDataMemroy->nextptr() >= 10) {
//        for (int i = 0;i<10;i++)
//        {
//            auto tdata = testDataMemroy->at(i);
//            testDataMemroy->remove(tdata);
//        }
//    }
//    RLogDbg("total max count = %d",testDataMemroy->getRMemoryInfo()->totalcount);
//    RLogDbg("current prt count = %d",testDataMemroy->getRMemoryInfo()->curnullptr);
//
//    RLogDbg("last data = %d",testDataMemroy->at(testDataMemroy->getRMemoryInfo()->curnullptr - 1).getTime1());
//    TestData testData;
//    testData.timestmap();
//    RLogDbg("made data = %d",testData.getTime1());
//    testDataMemroy->insert(testData);
//    RLogDbg("new data = %d",testDataMemroy->at(testDataMemroy->getRMemoryInfo()->curnullptr-1).getTime1());
    sleep(3);
    return 0;
}

TestProcUnit::TestProcUnit(RProcUnitRegisterIF &serverRegisterIf) : RProcUnit(serverRegisterIf) {}

TestProcUnit::TestProcUnit() {}

int TestProcUnit::finProc() {
    return 0;
}

